ORBstreams.h++ examples

IDL File

With ORBstreams.h++ a C++ collection can be passed directly. The IDL file would look like this:

opaque RWSlistCollectable;
interface Account
{
  RWSlistCollectable getTransactions();
    .
    .
    .
};

C++ Object Implementation

With ORBstreams.h++, the object streams its state to and from a virtual stream:

class Transaction : public RWCollectable
{
  RWDECLARE_COLLECTABLE(Transaction)
public:
  enum TransType {unknown, withdrawal, deposit};
  Transaction();
  Transaction(float amt, TransType type, RWDate d, RWTime t);
  virtual ~Transaction();
  void saveGuts(RWvostream &strm) const
  {
    // stream object state to a virtual output stream
    RWCollectable::saveGuts(strm);
    strm << amount_ << (short)type_ << date_ << time_;        void restoreGuts(RWvistream &strm)          // stream object 
state from a virtual input stream      RWCollectable::restoreGuts(strm);      strm>> amount_ >> (short &)type_ 
>> date_ >> time_;
  }
private:
  // internal state of object
  float amount_;
  TransType type_;
  RWDate date_;
  RWTime time_;
};

Server Object Implementation

With ORBstreams.h++ the server object can return the collection directly:

class Account_i {
public:
  Account_i();
  RWSlistCollectable *getTransactions(
                                CORBA_Environment &IT_env)
  {
    return new RWSlistCollectable(transactions_);
  };
private:
  RWSlistCollectable transactions_;
};

DEF_TIE_Account(Account_i)



Client Code

With ORBstreams.h++ the collection is ready to use; no translation is necessary. The client code would look like this:

RWSlistCollectable *transactionList;
// first, bind to object...
// then call the server and get Rogue Wave type back
TRY 
{
  transactionList = theAccount->getTransactions(); 
}
CATCHANY 
{ 
  fatal ("Unexpected exception: ", IT_X);
}
ENDTR


Back to ORBstreams.h++

© Copyright 1995, Rogue Wave Software, Inc.